package com.xiaohu.demo.utils.pageModel;

import java.util.List;

public class PageModel {
	private int pageNo;
	private int pageSize;
	private int totalRecord;//总记录条数
	private int totalPage;//总页数
	private int startIndex;//开始的
	private int start;
	private int end;
	private List pageData;//查询的结果
	private String sql;
	
	public PageModel() {}
	
	public PageModel(int pageNo, int pageSize, int totalRecord) {
		super();
		this.pageNo = pageNo;
		this.pageSize = pageSize;
		this.totalRecord = totalRecord;
		
		//计算从第几条开始
		this.startIndex = (pageNo-1) * pageSize;
		//计算总页数
		this.totalPage = totalRecord % pageSize == 0 ? totalRecord/pageSize :totalRecord/pageSize +1;
		
		if (this.totalPage <= 5) {
			// 总页数都小于5，那么end就为总页数的值了。
			this.end = this.totalPage;
		} else {
			// 总页数大于5，那么就要根据当前是第几页，来判断start和end为多少了，
			this.start = pageNo - 2;
			this.end = pageNo + 2;

			if (start < 0) {
				// 比如当前页是第1页，或者第2页，那么就不如和这个规则，
				this.start = 1;
				this.end = 5;
			}
			
			if(this.end > this.totalPage){
                  //比如当前页是倒数第2页或者最后一页，也同样不符合上面这个规则
                 this.end = this.totalPage;
                 this.start = this.end - 5;
            }
        }
	}
	
	
	public String getSql() {
		return sql;
	}

	public void setSql(String sql) {
		this.sql = sql;
	}

	public int getStartIndex() {
		return startIndex;
	}
	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}
	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalRecord() {
		return totalRecord;
	}
	public void setTotalRecord(int totalRecord) {
		this.totalRecord = totalRecord;
	}
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	
	public int getStart() {
		return start;
	}
	public void setStart(int start) {
		this.start = start;
	}
	public int getEnd() {
		return end;
	}
	public void setEnd(int end) {
		this.end = end;
	}
	public List getPageData() {
		return pageData;
	}
	public void setPageData(List pageData) {
		this.pageData = pageData;
	}
}
